document.addEventListener('DOMContentLoaded', function () {
    $(function () {
        $('header').load('./html/common/header.html', function () {
            let Img = document.querySelector('#loginFor');
            imgFlag = localStorage.getItem('img');
            if (imgFlag !== null) {
                Img.innerHTML = imgFlag;
                Img.href = 'javascript:void(0)';
            } else {
                Img.innerHTML = `<span class="iconfont icon-yonghutouxiang"></span>`;
                Img.href = './login.html';
            }
            // 头部导航栏的js动画
            var navs = document.getElementById('nav').getElementsByTagName('a'),
                line = document.getElementById('line');

            // 计时器
            var timer = null;

            // 位置初始化
            line.style.left = 0;

            Array.from(navs).forEach(function (item, index) {
                navs[index].onmouseover = function () {
                    localStorage.setItem('index', index);
                    if (timer) {
                        clearTimeout(timer);
                    };
                    var startPos = parseInt(line.style.left);
                    var targetPos = this.offsetLeft;
                    move(startPos, targetPos);
                }
            })

            function move(start, end) {
                // 缓冲运动的核心
                var step = (end - start) / 10;
                // 根据起点与终点的不同进行取整
                if (step > 0) {
                    step = Math.ceil(step);
                } else {
                    step = Math.floor(step);
                }
                start = start + step;
                line.style.left = start + 'px';

                if (start == end) {
                    clearTimeout(timer);
                } else {
                    timer = setTimeout(function () {
                        move(start, end);
                    }, 12)
                }
            }
            const link = document.querySelector('#link-2');
            link.addEventListener('click', function () {
                // console.log(1);
                // WriteCookie()
            })
        })
    })
    $(function () {
        $('footer').load('./html/common/footer.html', function () {

        })
    })
})

